import time
import keyboard
from time import sleep
from helper import *
from login import *
from drv import drv
import regex as re
from pprint import pprint
import difflib


# 链接定义
link_day = "https://pc.xuexi.cn/points/exam-practice.html"


# 元素定义
info1 = {
    'tihao' : {'xpath': "//div[@class='pager']/span"},
    'tiliang' : {'xpath': "//div[@class='pager']", 're':r'(?<=\/)(\d{1,2})'},
    'tixing' : {'xpath': "//div[@class='q-header']"},
    'abcd' : {'list':True, 'xpath': "//div[@class='q-answers']/div", 're':r'(?<=[A-F]\s{0,2}\.\s{0,2})(\S{1,100})'},
    'tips' : {'xpath': "//div[@class='ant-popover-inner-content']/div"},
    'answer' :  {'list':True, 'xpath': "//div[@class='ant-popover-inner-content']/div/font"},
    'showtips' : {'xpath': "//div[@class='q-footer']/span"},
    'qbody_inputs' : {'xpath': '//div[@class="q-body"]/div/input'},
    'submit' : {'xpath': '//div[@class="action-row"]/button'}
}



jy = drv()
login_xuexi(jy, '杨凡')
jy.driver.get(link_day)
time.sleep(5)
jy.info = info1
while True:
    jy.click('showtips')
    if jy.getText('tihao') == jy.getText('tiling'):
        break
    if jy.getText('tixing') == '单选题':
        jy.clickByText('el_abcd', jy.getText('answer'))
        jy.click('submit')
    elif jy.getText('tixing') == '多选题':
        for i in jy.getTexts('answer'):
            jy.clickByText('el_abcd', i)
        jy.click('submit')
    elif jy.getText('tixing') == '填空题':
            answer = jy.getTexts('answer')
            for i in range(len(answer)):
                jy.input('qbody_inputs', answer[i], i)
            jy.click('submit')
    sleep(5)
jy.driver.quit()
exit()
